package org.bing.engine.utility.codec;

import java.io.IOException;
import java.io.StringWriter;

public class SimpleObjectCodec {
    private static final SimpleReflectEncoder encoder = new SimpleReflectEncoder();
    private static final SimpleReflectDecoder decoder = new SimpleReflectDecoder();

    public String encode(Object obj) {
        StringWriter sw = new StringWriter();
        try {
            encoder.encode(obj, sw);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return sw.toString();
    }

    public Object decode(String str) {
        try {
            return decoder.read(str);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
